New to Rust? Grab our free Rust for Beginners eBook Get it free →
Install MySQL on macOS with Homebrew

Homebrew gives you the shortest path to a local MySQL server on macOS, but an install command alone does not prove that the server is running or that the client can connect. I checked the Homebrew mysql formula and built this sequence around the package, service, security, and connection checks it documents.
Use this route when you need a local database for development. You will install MySQL, start it as a Homebrew service, secure the initial account, and run a query that confirms the server answers the client.
Check Homebrew and existing database servers
Open Terminal and confirm that Homebrew is available before installing anything. The command prints Homebrew information when it is installed, and it tells you to install Homebrew when it is missing. Do not continue with the MySQL commands until this check succeeds.
brew --version
Check for an existing MariaDB or Percona Server installation before you add MySQL. Homebrew lists MariaDB and Percona Server as conflicts for its mysql formula because these packages install overlapping binaries.
brew list --formula | grep -E '^(mysql|mariadb|percona-server)'
An empty result means Homebrew does not report one of those formulae. If you see a database server that you still need, decide which server should own the mysql command before changing packages. Replacing it without a backup can break local projects that depend on its data directory or configuration.
Install the MySQL formula
The Homebrew formula page publishes the install command and the binaries that arrive with the package. Install the unversioned mysql formula when you want Homebrew’s default supported MySQL line.
brew install mysql
The command downloads a MySQL bottle for your Mac when one is available, then places the server, client, and administration tools under Homebrew’s prefix. Do not add a versioned formula merely because an older tutorial uses one. Use a versioned package only when an application has a documented compatibility requirement.
Before you accept a version constraint from an application, identify what it constrains. An ORM, migration tool, or hosted database may require a server release family, while a command-line tutorial may only require a compatible client. Those are different decisions, and installing an older server can add an upgrade task you did not need.
Homebrew reports the installed formula and its version with this command. Run it after installation if a project gives you a minimum supported release.
brew info mysql
The formula page also documents upgrade notes for moving from older MySQL releases. Treat a server upgrade as a data change, not as a package tidy-up. Back up databases and read the release-specific path before changing a server that already owns local data.
Homebrew’s formula page also lists mysql.server, mysql_secure_installation, mysqladmin, and mysqldump among the installed binaries. That list matters because the rest of this guide uses those tools instead of asking you to hunt through a package installer.
Start MySQL and secure the local account
Installing the package and starting the database are separate actions. Start the service first, then run the security program after the server can accept a connection.
Start the service
Homebrew can start MySQL now and register it for future logins. This is the most convenient choice for a development machine that uses MySQL regularly. The service listing will show whether that startup step succeeded.
brew services start mysql
Check the service state before moving on. A started service should appear with a status that tells you it is running under the macOS launch service manager.
brew services list
Homebrew also documents a direct server command for cases where you do not want login startup. Use the service route for this guide because it gives you the matching stop command and a visible service status. The same command family makes later diagnosis less confusing.
Run the security setup
Homebrew says its MySQL database starts without a root password and allows local connections by default. Run the security program after the service starts so you can set the local account policy and remove defaults that you do not need.
mysql_secure_installation
The prompts vary by MySQL release and by choices already stored on your machine, so a copied transcript is less useful than the decisions behind it. Set a password when the tool asks, remove anonymous accounts unless you have a tested local reason to retain them, and remove the test database when no project depends on it.
The security program changes server accounts and defaults. It does not create a separate application user, choose a database name, or configure remote access. Keep those tasks separate so you can tell whether a later application error comes from the installation or from its own connection settings.
For a project, create a user with only the privileges that project needs after the version query succeeds. That user can be replaced or removed with the project. Root remains an administrative account instead of a password copied into an application configuration file.
Keep remote root access disabled for a local development server. Remote access needs its own network, user, firewall, and TLS decisions. This installation flow only creates a local server.
Verify the server with the MySQL client
Connection verification is the step that separates a completed install from a package that merely downloaded. Connect as root and ask the server for its version.
mysql -u root -p -e 'SELECT VERSION();'
Enter the password you set in the security program. A working setup prints one row containing the server version.
A password rejection tells you the client reached MySQL but the account credentials need attention. A connection refusal points back to the service state rather than the password.
The command is intentionally small. It checks the client executable, the local socket or connection route, authentication, and SQL execution in one step without creating a database or table that you must remove later.
Read the failure as a stage marker. A shell error happens before the client runs, an access-denied error happens after the client reaches MySQL, and a connection error means MySQL is not accepting the requested local connection. Each result changes the next command, which is why the version query belongs before any application setup.
Do not use the root login as an application smoke test. It proves the administrative account works, but applications should use a separate user and a known database. Run the version query first, then add project credentials after you know the server and client route work.
A local install also gives you a clean boundary for experiments. You can create a test database, load a small fixture, and remove both when you are finished without touching a shared server. Keep the server local until your project has an explicit deployment and access plan.
Fix the first installation failures
Most first-run failures belong to one of two places. Either the shell cannot find the client binary, or the server has not started successfully.
mysql is not found
If Terminal reports that mysql is not found, confirm that Homebrew installed the formula and inspect the formula’s prefix. This avoids guessing where Homebrew placed the package on Apple Silicon or Intel hardware.
brew --prefix mysql
brew list mysql | grep '/bin/mysql$'
If the client exists under the formula prefix but the shell still cannot find it, inspect your Homebrew shell setup before adding a hard-coded path. Homebrew’s own post-install output and shell environment guidance should determine the change because the prefix differs by architecture and installation choice.
The service does not start
First check the service listing, then inspect Homebrew’s MySQL information. The formula warns that an existing configuration file such as /etc/my.cnf or /etc/mysql/my.cnf can interfere with a Homebrew-built server.
brew services list
brew info mysql
Do not delete a configuration file because it appears in a warning. Read it first and determine which MySQL or compatible server created it. A stale configuration can be moved aside after you record its contents, while an active project’s configuration needs a planned migration.
Choose the official installer when Homebrew is not your route
Homebrew is useful when you want package management and service control from Terminal. The official MySQL macOS documentation and MySQL Downloads page provide the Community Server installer route when your team requires the vendor package or you do not use Homebrew.
Keep one installation method for one local server. Mixing a DMG installation with a Homebrew formula can leave two server binaries, two data directories, or a client that connects to a different server than the one you started. Choose the route before you create databases or application users.
Stop the service when you are finished
Stop MySQL through the same service manager that started it when you no longer need the local database. The command leaves the installed package and data directory in place, so you can start it again for the next project.
brew services stop mysql
Before you build an application on the server, repeat the version query and create a dedicated database user for that application instead of using root. That keeps the installation check separate from the permissions your project will need.
Sources: Homebrew mysql formula, MySQL macOS installation documentation, and MySQL Downloads.




